package com.yh.jandan.ext;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

import javax.management.RuntimeErrorException;

import org.apache.commons.io.FileUtils;

import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.yh.jandan.controller.JandanController;
import com.yh.jandan.controller.MeiziController;
import com.yh.jandan.model.Config;

public class Init {
	
	public static void initData ( ) throws Exception {
		Config pconfig = Config.dao.findFirst ( "select * from config where name=?" , "psize" );
		Config cconfig = Config.dao.findFirst ( "select * from config where name=?" , "csize" );
		Config aconfig = Config.dao.findFirst ( "select * from config where name=?" , "autocatch" );
		JandanController.setPAGESIZE ( Integer.parseInt ( pconfig.getVal ( ) ) );
		JandanController.setAutocatch ( !aconfig.getVal ( ).equals ( "false" ) );
		LocalApp.setSize ( Integer.parseInt ( cconfig.getVal ( ) ) );
	}
	
	public static void initKey ( String webkey ) throws Exception {
//		if ( !new File ( webkey ).exists ( ) ) throw new FileNotFoundException ( webkey );
		Prop p = PropKit.use ( webkey );
		for ( Object name : p.getProperties ( ).keySet ( ) ) {
			MeiziController.webkey_count_max.put ( name.toString ( ) , p.getInt ( name.toString ( ) , 100 ) );
			MeiziController.webkey_count.put ( name.toString ( ) , 0 );
		}
	}
}
